<template>
  <div class="custom-body" :style="borderStyle">
    <div v-if="showHeader" class="custom-header" :style="titleStyle">
      <div class="header-body" :style="headerBottom">
        <div v-if="temp.sfxs === true" class="header-icon"><i :class="temp.lmtb" /></div>
        <div class="header-title" :style="titleFont"><span class="title-span">{{ temp.lmmc }}</span></div>
        <div v-if="temp.isMore === true" :style="titleFont" class="header-icon">
          更多
        </div>
      </div>
    </div>
    <div class="custom-content">
      <el-empty v-if="dataList === null || dataList.length === 0" :image-size="100" />
      <div v-for="item in dataList" :key="item.id" class="container-li">
        <service-list :key="item.id" :item="item" @fact-entity="openEntity" />
      </div>
    </div>
  </div>
</template>

<script>
import { queryAllParent } from '@/api/config/special';
import { isEmpty } from 'lodash';
import ServiceList from './common/ServiceItem';
import { openEntity } from '@/mixins/template';
export default {
  name: 'PortalNewPcCustomServiceV2',
  components: { ServiceList },
  mixins: [openEntity],
  props: {
    temp: {
      type: Object,
      default() {
        return {};
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      columns: [],
      dataList: [],
      customStyle: {},
      fontColor: {},
      headerBottom: {},
      customStyleTow: {},
      titleStyle: {},
      bodyStyle: {},
      titleFont: {},
      setting: [],
      borderStyle: {}
    };
  },
  computed: {
    themes() {
      return this.$store.getters.theme;
    }
  },
  watch: {
    temp: {
      handler(newData, oldData) {
        if (this.showHeader === true) {
          const pzx = JSON.parse(newData.data.pzx);
          this.columns = pzx;
          this.setting = pzx;
        } else {
          const pzx = JSON.parse(newData.pzx);
          this.setting = pzx.data;
          this.columns = pzx.data;
        }
        this.initData();
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    themes: {
      handler(val, oldVal) {
        this.borderStyle.borderRadius = val.bkdx;
        if (this.temp.sfxsbk === true) {
          this.borderStyle.border = '1px solid ' + val.bkys;
        }
        if (this.temp.bkyy === true) {
          this.borderStyle.boxShadow = '0 2px 4px rgba(0, 0, 0, .12)';
        }
        this.borderStyle.background = val.columnGroundColor;
        this.borderStyle.color = val.fontColor;
        this.titleStyle.background = val.columnTitleGroundColor;
        this.titleStyle.color = val.columnTitleFontColor;
        this.titleStyle = Object.assign({}, this.titleStyle);
        this.borderStyle = Object.assign({}, this.borderStyle);
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  },
  methods: {
    initData() {
      queryAllParent().then(res => {
        const { data } = res;
        if (!isEmpty(data)) {
          this.dataList = data.data;
        }
      }).catch(() => {
        console.log('初始化数据失败！');
      });
    }
  }
};
</script>

<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  display: flex;
  flex-flow: column nowrap;
  background-color: #ffffff;
  border-radius: 4px;
  padding: 0px 0px 10px 0px;
  box-sizing: border-box;
}
.custom-header {
  width: 100%;
  height: 40px;
  flex: 0 1 auto;
  padding: 0px 10px;
  box-sizing: border-box;
  line-height: 40px;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
}
.header-body{
  width: 100%;
  height: 100%;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  flex-flow: row nowrap;
}

.header-icon {
  width: 40px;
  height: 40px;
  flex: 0 1 auto;
  text-align: center;
  color: #409EFF;
}
.title-span {
  height: 40px;
  padding: 12px 5px;
  box-sizing: border-box;
  line-height: 40px;
  text-align: center;
}
.header-title {
  height: 40px;
  flex: 1 1 auto;
}
.custom-content {
  width: 100%;
  height: auto;
  flex: 1 1 auto;
  overflow: hidden;
  box-sizing: border-box;
}

.container-li:hover {
  box-shadow: 0 0 8px 0 rgba(0,0,0,.1);
}
.container-li:hover .container-li-top {
  color: #276eed;
}
.container-li:hover .container-content {
  border: none;
}

.el-scrollbar >>> .el-scrollbar__wrap {
  overflow-x: hidden;
  overflow-y: auto;
}
</style>
